package com.elinkway.infinitemovies.http.parser;

import com.elinkway.infinitemovies.bean.TopicDetail;
import com.elinkway.infinitemovies.bean.TopicDetailList;

import org.json.JSONArray;
import org.json.JSONObject;

public class TopicDetailParser extends LVideoMobileParser<TopicDetailList> {

	@Override
	public TopicDetailList parse(JSONObject data) throws Exception {
		TopicDetailList topicDetail = new TopicDetailList();
		topicDetail.setDesc(data.optString("shortdesc"));
		topicDetail.setPic(data.optString("pic"));
		topicDetail.setName(data.optString("name"));
		topicDetail.setSubName(data.optString("subname"));
				JSONArray arr = data.getJSONArray("data");
				for (int i = 0; i < arr.length(); i++) {
					TopicDetail topic = new TopicDetail();
					JSONObject obj = arr.getJSONObject(i);
					topic.setAlbumId(obj.optString("albumid"));
					topic.setName(obj.optString("name"));
					topic.setSubName(obj.optString("subname"));
					topic.setPoster(obj.optString("poster"));
					topic.setPlayUrl(obj.optString("playurl"));
					if (obj.has("rating")) {
						topic.setRating(String.format("%.1f",obj.optDouble("rating", 0.0)));
					}
					topic.setIsEnd(obj.optString("isend"));
					topic.setNowepisodes(obj.optString("nowepisodes"));
					topic.setEpisodes(obj.optString("episodes"));
					topic.setVideoId(obj.optInt("videoid"));
					topic.setVideotype(obj.optString("vt"));
					topicDetail.getTopics().add(topic);
				}
			return topicDetail;
	}

}
